import store from '../store/index';
import router from '../router/index';
export const tabs = [
  {
    type: "admin",
    icon: "icon-zhanghao",
    text: "用户信息",
    path: "/user",
    list: [
      {
        icon: "icon-wodexinxi",
        text: "业主信息",
        path: "/user/userinfo",
      },
      {
        icon: "icon-keshihua",
        text: "业主信息可视化",
        path: "/user/infoEchans",
      },
    ],
  },
  {
    type: "admin",
    icon: "icon-yijianguanli",
    text: "意见管理",
    path: "/opinion",
    list: [],
  },
  {
    type: "admin",
    icon: "icon-gongshilan",
    text: "公示栏管理",
    path: "/Property",
    list: [],
  },
  {
    type: "admin",
    icon: "icon-cheliangguanli1",
    text: "车辆管理",
    path: "/vehicle",
    list: [],
  },
  {
    type: "admin",
    icon: "icon-cheweiguanli",
    text: "车位管理",
    path: "/parkingLot",
    list: [],
  },
  {
    type: "user",
    icon: "icon-wodexinxi",
    text: "我的信息",
    path: "/ownerINfo",
    list: [],
  },
  {
    type: "user",
    icon: "icon-gongshilan",
    text: "公示栏",
    path: "/eedback/Publicity/",
    list: [],
  },
  {
    type: "user",
    icon: "icon-baoxiuwuye",
    text: "报修物业",
    path: "/eedback/repair/",
    list: [],
  },
  {
    type: "user",
    icon: "icon-yijianguanli",
    text: "意见反馈",
    path: "/eedback/feedback/",
    list: [],
  },
  {
    type: "user",
    icon: "icon-wuyefeiyongchuzhang",
    text: "物业费管理",
    path: "/propertyfee",
    list: [],
  }
]
export function chantabs() {
  return new Promise((resolve, reject) => {
    let data = localStorage.getItem('xm-token')
    if (!data) return
    data = JSON.parse(data)
    let type = data.type
    let tabArr = tabs.filter(item => {
      return item.type == type
    })
    store.commit('config/changeTabs',tabArr)
    let arr=JSON.parse(JSON.stringify(tabArr))
    arr.push({
      path: '/vel/index',
      name: 'index',
      text: '首页',
      list: []
    })
    // 添加动态路由
    let routesData = (event) => {
      for (const item of event) {
        function fun() {
          let obj = {
            path: item.path,
            name: item.text,
            meta: {
              title: item.text,
              index:item.index
            },
          }
          if (item.name == 'index') {
            obj.meta.index=2
            obj.component = () => import(/* webpackChunkName: "page" */ `@/page/index/component`)
          } else {
            obj.component = () => import(/* webpackChunkName: "page" */ `@/views${item.path}`)
          }
          // 一个一个的添加,Home 要往name为Home的路由的子路由中添加,如果不添加子路由就直接写路由对象
          router.addRoute('Home', obj)

        }
        if (item.list && !item.list.length) fun()
        if (!item.list) fun()
        // 递归遍历二级路由
        if (item.list && item.list.length) routesData(item.list)
      }
      // 该方法即将被弃用
      // router.addRoutes(routes)
    }
    routesData(arr)

    setTimeout(() => {
      resolve()
    }, 0);
  })

}